<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar bg-white shadow">
        <div class="btn-group tool-button mt5">
            <el-date-picker
                    v-model="searchDate"
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    align="right"
                    size="medium"
                    :default-time="['00:00:00', '23:59:59']"
                    value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
        </div>
        <!--按币种搜索-->
        <div class="btn-group tool-button mt5">
            <el-select v-model="pageForm.currencyId" placeholder="请选择币种"
                       size="medium"
            >
                <el-option
                        v-for="item in currencies"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                >
                </el-option>
            </el-select>
        </div>
        <div class="btn-group tool-button mt5">
            <el-input placeholder="用户名、昵称、手机、单号" v-model="pageForm.keyword"
                      @keyup.enter.native="doSearch" size="medium">
                <el-button slot="append" icon="el-icon-search" @click="doSearch"></el-button>
            </el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-checkbox v-model="isInside">不统计内部账号</el-checkbox>
        </div>
    </el-row>

    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                @sort-change='pageOrder'
                size="small"
                header-align="center"
                :summary-method="getSummaries"
                border
                show-summary
                style="width: 100%"
                :default-sort="{prop: 'opAt', order: 'descending'}"
        >
            <el-table-column
                    label="领取记录单号"
                    header-align="center"
                    prop="no"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="红包单号"
                    header-align="center"
                    prop="redPacketNo"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="用户名"
                    header-align="center"
                    prop="userName"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="用户昵称"
                    header-align="center"
                    prop="nickName"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="用户名"
                    header-align="center"
                    prop="userName"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="手机号"
                    header-align="center"
                    prop="phone"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="币种"
                    header-align="center"
                    prop="currencyName"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="金额"
                    header-align="center"
                    prop="amount"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="编号"
                    header-align="center"
                    prop="packetNo"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    sortable
                    label="创建时间"
                    header-align="center"
                    align="center"
                    prop="opAt">
                <template slot-scope="scope">
                    {{formatAt(scope.row.ctAt)}}
                </template>
            </el-table-column>

            <el-table-column
                    sortable
                    label="打开时间"
                    header-align="center"
                    align="center"
                    prop="openAt">
                <template slot-scope="scope">
                    {{formatAt(scope.row.openAt)}}
                </template>
            </el-table-column>

        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>

</div>
<script>
    let vue = new Vue({
        el: "#app",
        data: function () {
            return {
                pickerOptions: {
                    disabledDate: function (time) {
                        return time.getTime() > new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000);
                    },
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                addDialogVisible: false,
                searchDate: [],
                pageForm: {
                    keyWord: "",
                    currencyId: "",
                    searchDate: "",
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    pageOrderName: "opAt",
                    pageOrderBy: "descending",
                    conditionData: "",
                },
                tableData: [],
                sum: 0,
                currencies: [],
                loading: false,
                isInside: true,
            }
        },
        methods: {
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                if (self.searchDate) {
                    self.pageForm.searchDate = self.searchDate.toString();
                } else {
                    self.pageForm.searchDate = "";
                }
                self.pageForm.conditionData = "";
                if (self.isInside) {
                    if (self.pageForm.conditionData === "") {
                        self.pageForm.conditionData = "isInside";
                    } else {
                        self.pageForm.conditionData = self.pageForm.conditionData + ",isInside";
                    }
                }
                $.post(base + "/platform/user/redPacketRecord/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code === 0) {
                        self.tableData = data.data.pagination.list;
                        self.sum = data.data.sum;
                        self.pageForm.totalCount = data.data.pagination.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            getSummaries(param) {
                const {columns, data} = param;
                const sums = [];
                sums[6] = '合计USD';
                sums[7] = this.sum;
                return sums;
            },
            // 格式化时间
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm");
                return "";
            },
            // 币种列表
            getCurrencies: function () {
                var _this = this;
                $.post(base + "/platform/sys/currency/list", function (data) {
                    _this.currencies = data.data.map(ite => {
                        ite.name = ite.name + "(" + ite.rate + ")";
                        return ite;
                    })
                    ;
                    _this.currencies.push({
                        id: '',
                        name: '全部币种'
                    });
                }, "json");
            },
        },
        created: function () {
            this.pageData();
            this.getCurrencies();
        }
    });
</script>
<!--#
}
#-->